<template>
  <div
    class="tabbar-item"
    @click="toPath"
    :class="{ 'active-color': path === route.path }"
  >
    <div class="icon">
      <slot name="icon"></slot>
    </div>
    <div class="text">
      <slot name="text"></slot>
    </div>
  </div>
</template>

<script>
// 使用VueRouter
import { useRouter, useRoute } from 'vue-router'
export default {
  name: 'TabBarItem',
  props: {
    path: {
      type: String,
      default: ''
    }
  },
  setup(props) {
    const router = useRouter()
    const route = useRoute()
    let path = props.path
    // 定义路由跳转的方法
    function toPath() {
      router.push(path)
    }
    return {
      path,
      toPath,
      route
    }
  }
}
</script>

<style lang="scss" scoped>
.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  color: #000;
  .icon,
  .text {
    flex: 3;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .icon {
    flex: 5;
    display: flex;
    justify-content: center;
    align-items: flex-end;
  }
}
.active-color {
  color: var(--color-high-txt);
}
</style>